#ifndef THREADBASE_H
#define THREADBASE_H

#include <pthread.h>
#include <cstring>
#include <unistd.h>
#include <assert.h>
#include <stdio.h>

class ThreadBase
{
public:
    ThreadBase():
        _arg(NULL),
        _started(false),
        _stoped(false)
    {
        memset(_name, 0, sizeof(_name));
    }
    virtual ~ThreadBase()
    {

    }

public:
    void * _arg;
    char _name[16];
    bool _started;
    bool _stoped;

public:
    //Create OS thread.'this class run() function'is main thread function. It'll be passed
    //  'arg' as an argument.
    //  Name is 16 characters max including terminating NUL. Thread naming is
    //  implemented only for pthread, and windows when a debugger is attached.
    void start(void *arg_, const char *name_);

    //  stop the thread termination.
    void stop ();

    // return whether it is closed
    bool is_stop();

    //main thread function
    virtual void run(void *arg_);


private:
    pthread_t _descriptor;
};

#endif // THREADBASE_H
